package com.atguigu.yygh.hosp.controller;

import com.alibaba.excel.util.StringUtils;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.vo.hosp.HospitalSetQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atguigu.yygh.common.result.Result;
import java.util.List;

@Api(tags = "医院设置管理")
// 交给spring管理、返回数据
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
public class HospitalSetController {
    // 注入service
    @Autowired
    private HospitalSetService hospitalSetService;

    //http://localhost:8201/admin/hosp/hospitalSet/findAll
    @ApiOperation(value = "获取所有医院设置")
    // 1.查询医院设置表所有信息
    @GetMapping("findAll")
    public Result findAllHospitalSet(){
        // 调用service的方法
        List<HospitalSet> list = hospitalSetService.list();
        return Result.ok(list);
    }

    @ApiOperation(value = "逻辑删除医院设置")
    // 2.删除医院设置
    @DeleteMapping("{id}")
    public Result removeHospitalSet(@PathVariable Long id){
        boolean flag = hospitalSetService.removeById(id);
        if (flag){
            return Result.ok();
        }else
            return Result.fail();
    }

    // 3、条件查询带分页
    @PostMapping("findPage/{current}/{limit}")
    public Result findPageHospitalSet(@PathVariable long current,
                                      @PathVariable long limit,
                                      @RequestBody(required = false) HospitalSetQueryVo hospitalSetQueryVo){
        // 创建page对象,传递当前页,每页记录数
        Page<HospitalSet> page = new Page<>(current, limit);
        // 构造条件
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        String hosname = hospitalSetQueryVo.getHosname();    // 医院名称
        String hoscode = hospitalSetQueryVo.getHoscode();    // 医院编号
        if(!StringUtils.isEmpty(hosname))
            wrapper.like("hosname", hospitalSetQueryVo.getHosname());
        if(!StringUtils.isEmpty(hoscode))
            wrapper.eq("hoscode", hospitalSetQueryVo.getHoscode());

        // 调用方法实现分页查询
        Page<HospitalSet> pageHospitalSet = hospitalSetService.page(page, wrapper);
        return Result.ok(pageHospitalSet);
    }
    // 4、添加医院设置
    @PostMapping("svaHospitalSet")
    public Result saveHospitalSet(){


    }
    // 5、根据id货物医院设置

    // 6、修改医院设置

    // 7、批量删除医院设置

}
